<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.infodms.dms.common.Constant" %>
<%
	String contextPath = request.getContextPath();
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="/jstl/cout" prefix="c" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="${contextPath}/common/jsp_head_new.jsp" />
<title>经销商维护</title>
<script type="text/javascript">
var dealerLevel=<%=Constant.DEALER_LEVEL_01%>;
function doInit()
{  
   	var dl=document.getElementById("DEALERLEVEL").value;
	if(dealerLevel==dl)
	{
		document.getElementById("sJDealerCode").disabled="true";
		document.getElementById("dealerbu").disabled="true";
		document.getElementById("orgCode").disabled="";
		document.getElementById("orgbu").disabled="";
		
	}else
	{
		document.getElementById("sJDealerCode").disabled="";
		document.getElementById("dealerbu").disabled="";
		document.getElementById("orgCode").disabled="true";
		document.getElementById("orgbu").disabled="true";		
	}
	genLocSel('txt1','txt2','txt3','','',''); // 加载省份城市和县
}
<!--
//验证输入经销商代码是否已存在
	function chkDLR(dlrCode) {
		url = "<%=contextPath%>/sysmng/dealer/DealerInfo/chkDlr.json" ;
		makeCall(url, printErr, {dlrCode : dlrCode}) ;
	}

	function printErr(json) {
		if(json.errInfo == 1) {
			setText("DEALER_CODE") ;
			MyAlert("输入经销商代码已存在，请重新输入") ;
		}
    }

    function setText(obj,setValue) {
        if(!setValue) {
        	setValue = "" ;
        }
        
		document.getElementById(obj).value = setValue ;
    } 
//-->
</script>
</head>
<body>
<div class="navigation"><img src="<%=contextPath%>/img/nav.gif" />&nbsp;当前位置： 系统管理 &gt; 经销商管理 &gt;新增经销商</div>
 <form method="post" name = "fm" >
 <input id="COMPANY_ID" name="COMPANY_ID" type="hidden"/>
 <input type="hidden"  name="orgId"  value=""  id="orgId" />
 <input type="hidden"  name="sJDealerId"  value=""  id="sJDealerId" />
    <table width=100% border="0" align="center" cellpadding="1" cellspacing="1" class="table_query">
		  <tr>
		    <td class="table_query_2Col_label_6Letter">经销商代码：</td>
		    <td><input type='text'  class="middle_txt" name="DEALER_CODE"  id="DEALER_CODE" datatype="0,is_name,20"  value="" maxlength="20" onchange="chkDLR(this.value);"/>
		    </td>
		    <td class="table_query_2Col_label_6Letter">经销商名称：</td>
		    <td>
		    <input type='text'  class="middle_txt" name="DEALER_NAME"  id="DEALER_NAME" datatype="0,is_null,150"  value="" maxlength="150"/>
		    </td>
	      </tr>
	       <tr>
		    <td class="table_query_2Col_label_6Letter">经销商简称：</td>
		    <td>
		    <input type='text'  class="middle_txt" name="SHORT_NAME"  id="SHORT_NAME" datatype="0,is_null,75"  value="" maxlength="75"/>
		    </td>
		    <td class="table_query_2Col_label_6Letter">经销商等级：</td>
		    <td>
		    <label>
				<script type="text/javascript">
					genSelBoxExp("DEALERLEVEL",<%=Constant.DEALER_LEVEL%>,"-1",'',"short_sel","onchange='changeDealerlevel(this.value)'","false",'');
				</script>
		   </label>
		    </td>
	      </tr>
	        <tr>
		    <td class="table_query_2Col_label_6Letter">上级组织：</td>
		    <td>
		    <input type="text"  name="orgCode" size="15" value=""  id="orgCode" class="middle_txt" readonly="readonly"/>
		    <input name="orgbu"  id="orgbu" type="button" class="mark_btn" onclick="showOrg('orgCode','orgId','false')" value="&hellip;" />
		    </td>
		    <td class="table_query_2Col_label_6Letter">上级经销商：</td>
		    <td>
		    <input type="text"  name="sJDealerCode" size="15" value=""  id="sJDealerCode" class="middle_txt" readonly="readonly" />
		    
		    <input name="dealerbu"  id="dealerbu" type="button" class="mark_btn" onclick="showOrgDealer('sJDealerCode','sJDealerId','false','','true')" value="&hellip;" />
		    </td>
	      </tr>
	       <tr>
		    <td class="table_query_2Col_label_6Letter">经销商类型：</td>
		    <td>
		    <label>
				<script type="text/javascript">
					genSelBoxExp("DEALERTYPE",<%=Constant.DEALER_TYPE%>,"-1",true,"short_sel","onchange='dealerType(); '","false",'');
				</script>
		</label>
		    </td>
		    <td class="table_query_2Col_label_6Letter">经销商公司：</td>
		    <td>
		   <input class="middle_txt"  datatype="0,is_null,75"  id="COMPANY_NAME" style="cursor: pointer;" name="COMPANY_NAME" type="text" readonly="readonly" />
		   <input class="mark_btn" type="button" value="&hellip;" onclick="showCompanyA('<%=contextPath %>') ;"/>
		    </td>
	      </tr>
	        <tr id="labour_id" style="display: none">
	       <td class="table_query_2Col_label_6Letter">连锁店作业等级：</td>
		    <td>
		    <label>
				<script type="text/javascript">
					genSelBoxExp("DEALER_LABOUR_CODE",<%=Constant.DEALER_LABOUR_CODE%>,"<c:out value="${map.DEALER_LABOUR_TYPE}"/>",'',"short_sel",'',"false",'');
				</script>
		   </label>
		    </td>
		    <td class="table_query_2Col_label_6Letter">是否为DQV：</td>
		    <td>
		    <label>
				<script type="text/javascript">
					genSelBoxExp("IS_DQV",<%=Constant.IF_TYPE%>,'<%=Constant.IF_TYPE_NO%>',false,"short_sel",'',"false",'');
				</script>
		    </label>
		    </td>
	      </tr>
	      
	       <tr id="labour_id2" style="display: none">
	       <td class="table_query_2Col_label_6Letter">结算等级：</td>
		    <td>
		    <label>
				<script type="text/javascript">
					genSelBoxExp("BALANCE_LEVEL",<%=Constant.BALANCE_LEVEL%>,'','true',"short_sel",'',"false",'');
				</script>
		   </label>
		    </td>
		    <td class="table_query_2Col_label_6Letter">开票等级：</td>
		    <td>
		    <label>
				<script type="text/javascript">
					genSelBoxExp("INVOICE_LEVEL",<%=Constant.INVOICE_LEVEL%>,'',true,"short_sel",'',"false",'');
				</script>
		    </label>
		    </td>
	      </tr>
	      
	      
	      <tr>
	      <td class="table_query_2Col_label_6Letter">经销商状态：</td>
	      <td>
	      <label>
				<script type="text/javascript">
					genSelBoxExp("DEALERSTATUS",<%=Constant.STATUS%>,"-1",true,"short_sel",'',"false",'');
				</script>
		  </label>
	      </td>
	      <td class="table_query_2Col_label_6Letter">省份：</td>
	      <td> <select class="min_sel" id="txt1" name="province" onchange="_genCity(this,'txt2')"></select>  </td>
         </tr>
         <tr> 
          <td class="table_query_2Col_label_6Letter">地级市：</td>
	      <td><select class="min_sel" id="txt2" name="city" onchange="_genCity(this,'txt3')"></select> </td>  
	      <td class="table_query_3Col_label_6Letter" nowrap="nowrap">区/县：</td>
		  <td class="table_query_4Col_input" nowrap="nowrap"> <select class="min_sel" id="txt3" name="COUNTIES"></select></td>
	     </tr>
	     <tr>
	      <td class="table_query_2Col_label_6Letter">联系人：</td>
	      <td><input type="text"  class="middle_txt" name="linkMan"  id="linkMan"  datatype="1,is_name,10" value="" maxlength="10"/></td>
	      <td class="table_query_2Col_label_6Letter">电话：</td>
	      <td><input type="text"  class="middle_txt" name="phone"  id="phone" datatype="1,my_phone,25" value="" maxlength="25"/></td> 
	     </tr>
	      <tr>
	      <td class="table_query_2Col_label_6Letter">传真：</td>
	      <td><input type="text"  class="middle_txt" name="faxNo"  id="faxNo" value=""  datatype="1,my_phone,25" maxlength="25"/></td>
	      <td class="table_query_2Col_label_6Letter">Email：</td>
	      <td><input type="text"  class="middle_txt" name="email"  id="email" datatype="1,is_email,100" value="" maxlength="100"/></td>
	      </tr>
	      <tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">经销商评级：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
		<label>
				<script type="text/javascript">
					genSelBoxExp("DEALERCLASS",<%=Constant.DEALER_CLASS_TYPE%>,"-1",true,"short_sel",'',"false",'');
				</script>
		</label>
		</td>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">开票单位：</td>
		<td><input type="text"  class="middle_txt"  name="erpCode" id="erpCode" datatype="0,is_textarea,20" value="" maxlength="20"/></td> 
	</tr>
	<tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">税号：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
			<input type="text"  class="middle_txt" id="taxesNo" name="taxesNo" value=""  datatype="0,is_textarea,30" />
		</td>
		<td class="table_query_2Col_label_6Letter">邮编：</td>
	    <td><input type="text"  class="middle_txt" name="zipCode"  id="zipCode" value="" maxlength="10" datatype="1,is_digit_letter,30" /></td>
	</tr>
	<tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">乡：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
			<input type="text"  class="middle_txt" id="TOWNSHIP" name="TOWNSHIP" value=""/>
		</td>
		<td class="table_query_2Col_label_6Letter">法人：</td>
	    <td><input type="text"  class="middle_txt" name="LEGAL"  id="LEGAL" value=""/></td>
	</tr>
	<tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">站长电话：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
			<input type="text"  class="middle_txt" id="WEBMASTER_PHONE" name="WEBMASTER_PHONE" value=""/>
		</td>
		<td class="table_query_2Col_label_6Letter">值班电话：</td>
	    <td><input type="text"  class="middle_txt" name="DUTY_PHONE"  id="DUTY_PHONE" value=""/></td>
	</tr>
	<tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">开户行：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
			<input type="text"  class="middle_txt" id="BANK" name="BANK" value=""/>
		</td>
		<td class="table_query_2Col_label_6Letter">维修资源：</td>
	    <td>
		<label>
				<script type="text/javascript">
					genSelBoxExp("MAIN_RESOURCES",<%=Constant.MAIN_RESOURCES%>,"-1",true,"short_sel",'',"false",'');
				</script>
		</label>
		</td>
	</tr>
	<tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">行政级别：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
		<label>
				<script type="text/javascript">
					genSelBoxExp("ADMIN_LEVEL",<%=Constant.ADMIN_LEVEL%>,"-1",true,"short_sel",'',"false",'');
				</script>
		</label>
		</td>
		<td class="table_query_2Col_label_6Letter">形象等级：</td>
	    <td>
		<label>
				<script type="text/javascript">
					genSelBoxExp("IMAGE_LEVEL",<%=Constant.IMAGE_LEVEL%>,"-1",true,"short_sel",'',"false",'');
				</script>
		</label>
		</td>
	</tr>
	<!-- 
	<tr>
		<td class="table_query_3Col_label_6Letter" nowrap="nowrap">纳税级别：</td>
		<td class="table_query_4Col_input" nowrap="nowrap"> 
		<label>
				<script type="text/javascript">
					genSelBoxExp("TAX_LEVEL",<%=Constant.IMAGE_LEVEL%>,"-1",true,"short_sel",'',"false",'');
				</script>
		</label>
		</td>
		<td class="table_query_2Col_label_6Letter"></td>
	    <td></td>
	</tr>
	 -->
	      <tr>
	        <td class="table_query_2Col_label_6Letter">详细地址：</td>
	      	<td><textarea name="address" id="address" cols="40" rows="2" datatype="1,is_textarea,50" ></textarea></td>
	      </tr>
	
	      <tr>
	        <td class="table_query_2Col_label_6Letter">备注：</td>
	      	<td><textarea name="remark" id="remark" cols="40" rows="2" datatype="1,is_textarea,1000"></textarea></td>
	      </tr>
	 </table> 
     <table class=table_query>
	 <tr>
	 <td>
	<input type="button" value="保存" name="saveBtn" class="normal_btn" onclick="saveDealerInfo()"/>	
	<input type="button" value="返回" name="cancelBtn"  class="normal_btn" onclick="history.back();" /></td>
	</tr>
   </table>
</form>

<script type="text/javascript" >
function changeDealerlevel(value)
{
	if(dealerLevel==value)
	{
		document.getElementById("sJDealerCode").disabled="true";
		document.getElementById("dealerbu").disabled="true";
		document.getElementById("orgCode").disabled="";
		document.getElementById("orgbu").disabled="";
		document.getElementById("sJDealerCode").value="";
		document.getElementById("sJDealerId").value="";
	}else
	{
		document.getElementById("sJDealerCode").disabled="";
		document.getElementById("dealerbu").disabled="";
		document.getElementById("orgCode").disabled="true";
		document.getElementById("orgbu").disabled="true";
		document.getElementById("orgCode").value="";
		document.getElementById("orgId").value="";			
	}
}
function saveDealerInfo()
{    
	var text1=document.getElementById("txt1").value;
	var text2=document.getElementById("txt2").value;
	var DEALERTYPE=document.getElementById("DEALERTYPE").value;
	var DEALERSTATUS=document.getElementById("DEALERSTATUS").value;
	var DEALERCLASS=document.getElementById("DEALERCLASS").value;
	if(DEALERTYPE==""){
		MyAlert("经销商类型不能为空！");
		return;
		}
	if(DEALERSTATUS==""){
		MyAlert("经销商状态不能为空！");
		return;
	}
	//if(DEALERCLASS==""){
		//MyAlert("经销商评级不能为空！");
		//return;
	//}
	if(text1==""){
			MyAlert('省份输入不能为空！');
			return;
		}
	if(text2==""){
		MyAlert('城市输入不能为空！');
		return;
	}
	
	if(DEALERTYPE==<%=Constant.DEALER_TYPE_DWR%>){
		var BALANCE_LEVEL=document.getElementById("BALANCE_LEVEL").value;
		var INVOICE_LEVEL=document.getElementById("INVOICE_LEVEL").value;
		var DEALERLEVEL=document.getElementById("DEALERLEVEL").value;//经销商级别
		if(BALANCE_LEVEL==''){
			MyAlert('请选择结算等级!');
			return;
		}
		if(INVOICE_LEVEL==''){
			MyAlert('请选择开票等级!');
			return;
		}
		if(DEALERLEVEL==<%=Constant.DEALER_LEVEL_01%>){//一级经销商
			if(BALANCE_LEVEL!=<%=Constant.BALANCE_LEVEL_SELF%>){
				MyAlert('一级经销商结算等级必须选择 独立结算!');
				return;
			}
			if(INVOICE_LEVEL!=<%=Constant.INVOICE_LEVEL_SELF%>){
				MyAlert('一级经销商开票等级必须选择 独立开票!');
				return;
			}
			
		}else{//二级经销商
			if(BALANCE_LEVEL==<%=Constant.BALANCE_LEVEL_HIGH%>&&INVOICE_LEVEL==<%=Constant.INVOICE_LEVEL_SELF%>){
				MyAlert('结算等级为上级结算时,不能选择独立开票!');
				return;
			}
		}
	}
	
	var dl=document.getElementById("DEALERLEVEL").value;
	if(dealerLevel==dl)
	{
		var orgId=document.getElementById("orgId").value;
		if(orgId=="")
		{
			alert("请选择上级组织！");
			return;
		}
	}else
	{
		var sjId=document.getElementById("sJDealerId").value;
		if(sjId=="")
		{
			alert("请选择上级经销商！");
			return;	
		}
	}
	var companyId=document.getElementById("COMPANY_ID").value;
	if(companyId=="")
	{
		alert("请选择经销商公司！");
		return;	
	}
	if(submitForm('fm'))
	{
		sendAjax('<%=contextPath%>/sysmng/dealer/DealerInfo/checkDealerCode.json',showResultCodeCheck,'fm')
	}

}
function showResultCodeCheck(obj){
	var msg=obj.msg;
	if(msg=='true'){
		if(confirm("确认添加新的经销商信息吗？"))
		{
			fm.action = '<%=contextPath%>/sysmng/dealer/DealerInfo/saveDealerInfo.do';
		 	fm.submit();
		}		
	}else{
		MyAlert('经销商代码已经存在,请换其它代码!');
	}
}
function showCompanyA(path){ 
	OpenHtmlWindow(path+'/common/OrgMng/queryCompanyA.do',800,450);
}
function dealerType(){
	if($('DEALERTYPE').value==<%=Constant.DEALER_TYPE_DWR%>){
		$('labour_id').style.display='';
		$('labour_id2').style.display='';
	}
	else{
		$('labour_id').style.display='none';
		$('labour_id2').style.display='none';
	}
}
dealerType();
</script>

</body>
</html>
